<?php

namespace App\Http\Controllers\Admin;

use App\Http\Model\Logs;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;

class SettingController extends Controller
{
    /**
     * 网站设置
     * @return $this|array
     */
    public function settings(){
        check_auth();
        if($input=Input::except('_token')){
            $this->putConfig($input);
            return ['status'=>1,'msg'=>'完成'];
        }
        $cfg=Config::get('web');
        Logs::create(['username'=>Session::get('admin')['username'],'event'=>'修改了网站配置文件,网站设置']);
        return view('admin.settings')->with(['title'=>'网站设置','cfg'=>$cfg]);
    }

    /**
     * 写入配置文件
     * @param $data
     */
    public function putConfig($data){
        $path=base_path().'\config\web.php';
        $str='<?php
    return '.var_export($data,true).';';
        file_put_contents($path,$str);
    }
}
